package cjq.demo.thread.ch4_4;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2016/4/27.
 */
public class FactoriaCalculator implements Callable<Integer> {

    private Integer number;

    public FactoriaCalculator(Integer number){
        this.number = number;
    }

    public Integer call() throws Exception{
        int result = 1;
        if((number==0) || (number==1)){
            result = 1;
        }else{
            for (int i = 0; i < number; i++) {
                result*=i;
                TimeUnit.MILLISECONDS.sleep(20);
            }
        }

        System.out.println(Thread.currentThread().getName()+" "+ result);

        return result;
    }
}
